package org.jeecg.modules.demo.publicplace.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.demo.publicplace.entity.ZnzfPublic;
import org.jeecg.modules.demo.publicplace.mapper.ZnzfPublicMapper;
import org.jeecg.modules.demo.publicplace.service.IZnzfPublicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.LinkedList;
import java.util.List;

/**
 * @Description: 公共场所
 * @Author: jeecg-boot
 * @Date:   2022-04-11
 * @Version: V1.0
 */
@Service
public class ZnzfPublicServiceImpl extends ServiceImpl<ZnzfPublicMapper, ZnzfPublic> implements IZnzfPublicService {

    @Autowired
    private ZnzfPublicMapper znzfPublicMapper;

    /**
     * 根据projectId获取所有公共场所类型
     * @param projectId
     * @return
     */
    @Override
    public List<Integer> findAllPublicTypeById(String projectId) {
        List<Integer> resList = new LinkedList<Integer>();
        QueryWrapper<ZnzfPublic> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("DISTINCT type").eq("project_id", projectId);
        List<ZnzfPublic> znzfPublics = znzfPublicMapper.selectList(queryWrapper);
        System.out.println(znzfPublics.toString());
        znzfPublics.forEach(znzfPublic -> {
            resList.add(znzfPublic.getType());
            System.out.println(znzfPublic.getType());
        });
        return resList;
    }

    /**
     * 根据projectId获取所有公共场所类型
     * @param projectId
     * @param type
     * @return
     */
    @Override
    public List<ZnzfPublic> queryPublicPlaceByType(String projectId, int type) {
        LambdaQueryWrapper<ZnzfPublic> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper
                .eq(ZnzfPublic::getProjectId, projectId)
                .eq(ZnzfPublic::getType, type);
        List<ZnzfPublic> znzfPublicList = znzfPublicMapper.selectList(queryWrapper);
        if (znzfPublicList.size() == 0)
            return null;
        return znzfPublicList;
    }
}
